import _ from "lodash";
import {
  register,
  SPAN,
  XS,
  SM,
  MD,
  LG,
  XL,
  XXL,
} from "@/utils/plugins/resize";
// 搜索数据的模板格式
const searchTempGlo = {
    searchVal: "", // 搜索的值
    searchPro: "", // 字段名
    searchBy: "like", // link  =
    proDType: "String",
}
export default {
  props: {
    formConfig: {
      type: Array,
    },
    gridCol: {
      type: Object,
      default: {
        span: 8,
      },
    },
  },
  created() {
    register(this._uid, (size) => {
      switch (size) {
        case XS:
          if (this.gridCol.xs) {
            this.hiddenGrid = Math.floor(24 / this.gridCol.xs);
            break;
          }
        case SM:
          if (this.gridCol.sm) {
            this.hiddenGrid = Math.floor(24 / this.gridCol.sm);
            break;
          }
        case MD:
          if (this.gridCol.md) {
            this.hiddenGrid = Math.floor(24 / this.gridCol.md);
            break;
          }
        case LG:
          if (this.gridCol.lg) {
            this.hiddenGrid = Math.floor(24 / this.gridCol.lg);
            break;
          }
        case XL:
          if (this.gridCol.xl) {
            this.hiddenGrid = Math.floor(24 / this.gridCol.xl);
            break;
          }
        case XXL:
          if (this.gridCol.xxl) {
            this.hiddenGrid = Math.floor(24 / this.gridCol.xxl);
            break;
          }
        case SPAN:
          if (this.gridCol.span) {
            this.hiddenGrid = Math.floor(24 / this.gridCol.span);
            break;
          }

        default:
          break;
      }
    });
  },
  data() {
    const searchForm = Object.create(null);
    this.formConfig.forEach(function(item) {
      searchForm[item.name] = item.default || "";
    });
    return {
      expand: true,
      hiddenGrid: 4,
      searchForm
    };
  },
  mounted() {
    setTimeout(()=>this.getHeight(),0)
  },
  methods: {
    getHeight(){
      if(this.$refs.search){
        this.$parent.$emit('push-height',(this.$refs.search.clientHeight+10))
      }
    },
    toggle() {
      this.expand = !this.expand;
      this.$nextTick(()=>this.getHeight())
    },
    searchReset(){
      Object.keys(this.searchForm).forEach(key=>(this.searchForm[key] = ""))
      this.$emit('search',this.searchForm)
    },
    searchHandler(){
      this.$emit('search',this.searchForm)
    }
    
  },
};
